<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请咨询专家</title>
    <script type="text/javascript" src="../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script type="text/javascript" src="../../js/Tools.js"></script>
    <script type="text/javascript" src="../../js/login_common.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <style>

        body{
            padding: 10px 20px 10px 10px;
        }

        #schemeName{
            margin-top: 40px;
        }

    </style>
</head>
<body>

    <form class="layui-form" id="commentForm">
        <input type="hidden" id="schemeId"/>
        <div class='layui-form-item layui-form-text'>
            <div class='layui-form-label'>方案名称</div>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="schemeName" id="schemeName" />
            </div>
        </div>
        <div class='layui-form-item layui-form-text'>
            <label class='layui-form-label'>申请理由</label>
            <div class='layui-input-block'>
                <textarea placeholder='请输入您的申请理由' id='reason' name='reason' lay-verify='reason' class='layui-textarea'></textarea>
            </div>
        </div>
        <div class='layui-form-item'>
            <div class='layui-input-block'>
                <input type='button' class='layui-btn' lay-submit='' id="button" lay-filter='demo1' value="立即提交"/>
            </div>
        </div>


    </form>
    <script>
        //取上个页面传过来的方案id
        var schemeId=getQueryString("schemeId");
        var schemeName=getQueryString("schemeName");
        $(function () {
            $("#schemeName").text(schemeName);
        });

        layui.use(['form', 'layedit', 'laydate','tree','element','upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , element = layui.element
                , upload = layui.upload;

            //根据id查询方案信息
            var url = getRootPath() + "atsSchemeAction/selectById";
            var data = {schemeId: schemeId};
            $.post(url, data, function (obj) {
                $("#schemeId").val(obj.schemeId);
                $("#schemeName").val(obj.schemeName);
            }, "json");


            //自定义验证规则
            form.verify({
                reason: function (value) {
                    if (!value.length) {
                        return '申请理由不能包含空格';
                    }
                }
            });

            //监听提交
            form.on('submit(demo1)', function (data) {

                var url2 = getRootPath() + "atsSchemeAction/addExpert";
                var data2 = {schemeId: schemeId,saName:schemeName, applyForExp: $("#reason").val(),creater:window.loginObj.manager.manUser,applyForTime:getFormatDate(),remark:"atsScheme"};
                $.ajax({
                    url: url2,
                    type: "post",
                    data: data2,
                    dataType: "json",
                    success: function (obj) {
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }, error: function (e) {
                        alert('失败了');
                    }

                });
            });
        });

        //获取当前时间
        function getFormatDate() {
            var nowDate = new Date();
            var year = nowDate.getFullYear();
            var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
            var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
            var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
            var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
            var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }
    </script>
</body>
</html>